﻿@using GTAuto.DAL.DAL
@using GTAuto.DAL.Entities
@using GTAuto.DAL.Enums
@model GTAuto.DAL.Entities.GTModel
@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";

    SelectList selectList = ViewBag.brands;
    List<string> err = ViewBag.Errs;

    GTBrand brand = ViewBag.Brend;
    var propCats = DALPropertyCategory.Singleton.GetAll((BrandTypeEnum)brand.Type);
    List<GTModelModificationProperty> propss = ViewBag.Props;
    
    
}
<h4 class="alert_info">
    @if (Model.Id > 0)
    {
        <div>
            Редактирование модели</div>
    }
    else
    {
  
        <div>
            Создание новой модели</div>
    }
</h4>
@using (Html.BeginForm("Edit", "BrandModels", FormMethod.Post, new { @class = "jNice", enctype = "multipart/form-data" }))
{

    if (err != null && err.Count != 0)
    {

        foreach (var er in err)
        {

    <h4 class="alert_error">
        @er</h4>

        }
    }
    if (ViewBag.Succes != null)
    {
    <h4 class="alert_success">
        @ViewBag.Succes</h4>
    }

    @Html.Hidden("Id", Model.Id)
    <article class="module width_full">
        <header><h3>Данные о модели</h3></header>
        <div class="module_content">
            <fieldset>
                <label>Название</label>
                <input type="text" id="Name" name="Name" value="@Model.Name" />
            </fieldset>
             <fieldset>
                <label>Год</label>
                <input type="text" id="Year" name="Year" value="@Model.Year" />
            </fieldset>
            <fieldset >
                <label>Бренд:</label>
                @Html.DropDownList("BrandId", selectList)
            </fieldset>
             <fieldset>
                <label>Описание</label>
               <textarea rows="20" cols="1" name="Description" id="Description">@Model.Description</textarea>
            </fieldset>
          
          
          <fieldset style="width: 100%; float: left; margin-right: 3%;">
                 <label>
                    Лого(круп.) :</label><input type="file"  id="Logo" name="Logo" value="@Model.Logo" />
            </fieldset>

             @if (!string.IsNullOrEmpty(Model.Logo))
             {
                <p>
                    <img src="@string.Format("{0}/{1}", DALSettngs.Singleton.Get("BrendLogosAdminView").Value, Model.Logo)"/>
                </p>
             }
              <fieldset style="width: 100%; float: left; margin-right: 3%;">
                 <label>
                    Лого(мелк.) :</label><input type="file" class="text-long" id="LogoSmal" name="LogoSmal" value="@Model.LogoSmal" />
            </fieldset>
            
             @if (!string.IsNullOrEmpty(Model.LogoSmal))
             {
                <p>
                    <img src="@string.Format("{0}/{1}", DALSettngs.Singleton.Get("BrendLogosAdminView").Value, Model.LogoSmal)"/>
                </p>
             }
          

            <div class="clear"></div>
        </div>
        <footer>
            <div class="submit_link">
                <input type="submit" value="Сохранить" class="alt_btn">
            </div>
        </footer>
    </article>
   
    
    <article class="module width_full">
			<header><h3>Виды характеристик данной модели</h3></header>
				<div class="module_content">
					<p>Укажите виды характеристики даной модели</p>
				</div>
		</article>
    
    
             foreach (var cat in propCats)
             {
                 var props = DALModificationProperty.Singleton.GetByCategory(cat.Id);

    <article class="module width_full">
            <header><h3 class="tabs_involved">@cat.Name</h3>
            </header>
            <table class="tablesorter" cellSpacing="0">
                <tbody>
                     @foreach (var item in props)
                     {
                    <tr>
                        <td style="width:600px;">@item.Name
                        </td>
                        <td>
                            @{
                         var chcked = propss.Where(x => x.PropertyId == item.Id).SingleOrDefault() != null;
                            }
                                 
                                 @if (!chcked)
                                 {
                                      <input type="checkbox" name="@string.Format("prop_{0}", item.Id)"  id="@string.Format("prop_{0}", item.Id)" />
                                 }
                                 else
                                 {
                                      <input type="checkbox" checked="checked" name="@string.Format("prop_{0}", item.Id)"  id="@string.Format("prop_{0}", item.Id)" />
                                 }
                        </td> 
                    </tr>
                     }
                </tbody>
            </table>
        
        </article>
             }
}
<!-- end of post new article -->
<div class="spacer">
</div>
